package com.quartet.modules.equipment.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.quartet.modules.alarm.dto.TVehicleSecurityAlarmProcessingResponseDto;
import com.quartet.modules.equipment.dao.TAlarmProcessingInfoDao;
import com.quartet.modules.equipment.entity.TAlarmProcessingInfo;
import com.quartet.modules.equipment.service.TAlarmInfoService;
import com.quartet.modules.system.service.DictDetailServicePs;
import com.quartet.modules.vehicle.dto.TVehicleRealAlarmInfoRequestDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 报警信息表(TAlarmInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-05-04 12:10:02
 */
@Service("tAlarmInfoService")
public class TAlarmInfoServiceImpl extends ServiceImpl<TAlarmProcessingInfoDao, TAlarmProcessingInfo> implements TAlarmInfoService {

    @Autowired
    private DictDetailServicePs dictDetailServicePs;

    /**
     * 功能描述: 查询已处理的报警信息及处理信息
     * @author huipanxing huipanxing@chinasofti.com
     * @date 2021/6/3 11:31
     * @param tVehicleRealAlarmInfoRequestDto
     * @return java.util.List<com.quartet.modules.alarm.dto.TVehicleSecurityAlarmProcessingResponseDto>
     */
    @Override
    public List<TVehicleSecurityAlarmProcessingResponseDto> selectSecurityAlarmProcessingList(TVehicleRealAlarmInfoRequestDto tVehicleRealAlarmInfoRequestDto) {
        List<TVehicleSecurityAlarmProcessingResponseDto> tVehicleSecurityAlarmProcessingResponseDtoList = this.baseMapper.selectSecurityAlarmProcessingList(tVehicleRealAlarmInfoRequestDto);
        Map<String, List<TVehicleSecurityAlarmProcessingResponseDto>> collect = tVehicleSecurityAlarmProcessingResponseDtoList.stream().collect(Collectors.groupingBy(TVehicleSecurityAlarmProcessingResponseDto::getVehicleAlarmType));
        List<TVehicleSecurityAlarmProcessingResponseDto> tVehicleSecurityAlarmProcessingResponseDtoList1 = collect.keySet().stream().map(k -> {
            List<TVehicleSecurityAlarmProcessingResponseDto> vehicleSecurityAlarmProcessingResponseDtoList = collect.get(k);
            TVehicleSecurityAlarmProcessingResponseDto tVehicleSecurityAlarmProcessingResponseDto = vehicleSecurityAlarmProcessingResponseDtoList.get(0);
            int size = vehicleSecurityAlarmProcessingResponseDtoList.size();
            tVehicleSecurityAlarmProcessingResponseDto.setFirstAlarmTime(vehicleSecurityAlarmProcessingResponseDtoList.get(0).getAlarmTime());
            tVehicleSecurityAlarmProcessingResponseDto.setLastAlarmTime(vehicleSecurityAlarmProcessingResponseDtoList.get(size - 1).getAlarmTime());
            tVehicleSecurityAlarmProcessingResponseDto.setLastPosition(vehicleSecurityAlarmProcessingResponseDtoList.get(size - 1).getPosition());
            tVehicleSecurityAlarmProcessingResponseDto.setAlarmTypeLabel(dictDetailServicePs.getLabelByValueByCode(tVehicleSecurityAlarmProcessingResponseDto.getAlarmType()));
            return tVehicleSecurityAlarmProcessingResponseDto;
        }).collect(Collectors.toList());
        return tVehicleSecurityAlarmProcessingResponseDtoList1;
    }
}
